package com.anrongtec.zcpt.logo;

import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.base.BaseActivity;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 
 * @ClassName:引导页面
 * @Description: 引导页面
 * @author dongtianhao
 * @date 2016年6月23日 下午10:35:11
 *
 */
public class LogoActivity extends BaseActivity {
	private TimerTask MyTimer;
	private Timer time;
	private Intent intent;
	
	private ImageView iv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setTitleShow(false);
		setContentView(R.layout.activity_logo);
		initView();
	}

	protected void initView() {
		
		iv = (ImageView) findViewById(R.id.iv_logo);
		
		
		// 不触摸四秒跳转
		MyTimer = new TimerTask() {
			@Override
			public void run() {
				intent = new Intent(LogoActivity.this, LoginActivity.class);
				startActivity(intent);
				finish();
			}
		};
		time = new Timer();
		time.schedule(MyTimer, 4000);
	}

	// 触摸跳转
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			time.cancel();
			// DDApp.dApp.preferences.saveBoolean("isFirst", true);
			intent = new Intent(LogoActivity.this, LoginActivity.class);
			startActivity(intent);
			finish();
		}
		return super.onTouchEvent(event);
	}
	
	@Override
	protected void onDestroy() {
		if (time!=null) {
			time.purge();
			time = null;
		}
		if (iv.getDrawable() != null) {
			iv.getDrawable().setCallback(null);
			iv = null;
		}
		super.onDestroy();
	}

}
